<?php
require 'Db.class.php';
require 'Conf.class.php';

function mail_exists($mail){
 $bd=Db::getInstance();
 $query="SELECT id FROM suscribers WHERE email='".$mail."' LIMIT 1";
 $stmt=$bd->ejecutar($query);
 while($arr=mysql_fetch_array($stmt, MYSQL_ASSOC)){
  $row=$arr; 
  }
 return $row['id']; //Return the ID of the user.
	}
	
 function getEmail($id){
 $bd=Db::getInstance();
 $query="SELECT email FROM suscribers WHERE id='".$id."' LIMIT 1";
 $stmt=$bd->ejecutar($query);
 while($arr=mysql_fetch_array($stmt, MYSQL_ASSOC)){
  $row=$arr; 
  }
 return $row['email']; //Return the ID of the user.
 	}
 function getStep($id, $field){
 	$bd=Db::getInstance();
	$query="SELECT ".$field." FROM suscribers WHERE id='".$id."' LIMIT 1";
	$stmt=$bd->ejecutar($query);
	while($arr=mysql_fetch_array($stmt, MYSQL_ASSOC)){
	  $row=$arr; 
	  }
	 return $row[$field]; //Return the field of the user.
 	}
 function write($query){
  $bd=Db::getInstance();
  $stmt=$bd->ejecutar($query);
  return $bd->lastID();
 }
 
 function get_user_data($id, $password){
  $bd=Db::getInstance();
  $safe_salt=get_safe_salt();
  $query="SELECT * FROM suscribers WHERE id='".$id."' AND password='".md5($password.$safe_salt)."' LIMIT 1";
  $stmt=$bd->ejecutar($query);
  if($stmt[id]!=NULL){
  while($arr=mysql_fetch_array($stmt, MYSQL_ASSOC)){
  $row=$arr;
  return $row;
   }
  }
  else { $row='false'; }
  return $row; //Return the user data or false.
  }
  
  function get_safe_salt(){
   $bd=Db::getInstance();
   $var=$bd->getSalt();
   return $var;
   }
   

?>
